package com.mzy.linear_struct.subject;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @Author: codermzy
 * @Date: 2024/03/29/14:07
 * @Description:
 */
public class 击鼓传花 {

    public static void main(String[] args) {

        Deque<String> deque = new LinkedList<>();

        deque.offer("why");
        deque.offer("jams");
        deque.offer("kobe");
        deque.offer("curry");
        deque.offer("abc");
        deque.offer("cba");
        deque.offer("nba");
        deque.offer("mba");

        System.out.println(deque);
        hotPotato(deque, 4);

    }


    public static void hotPotato(Deque<String> deque, int num) {
        int count = 0;
        while (deque.size() > 1) {
            count++;
            if (count % num == 0) {
                deque.removeLast();
            } else {
                deque.addFirst(deque.removeLast());
            }

        }

        System.out.println(deque);
    }
}
